package com.example.service.impl;

import com.example.entity.Myorder;
import com.example.mapper.MyorderMapper;
import com.example.service.CustomerClient;
import com.example.service.OrderService;
import com.example.service.ProductClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private MyorderMapper mapper;
    @Autowired
    private ProductClient productClient;
    @Autowired
    private CustomerClient customerClient;
    @Override
    public boolean insertOrder(Integer custId,Integer proId) {
        Myorder myorder=new Myorder();
        myorder.setCustId(custId);
        myorder.setProId(proId);

        if(productClient.getProPrice(proId).get("proPrice")==null)
            return false;

        BigDecimal proPrice=new BigDecimal(productClient.getProPrice(proId).get("proPrice").toString());
        myorder.setOrderPrice(proPrice);
        myorder.setOrderNum(null);
        myorder.setOrderCreateTime(null);
        myorder.setOrderStatus("1");
        return mapper.insert(myorder)>0;
    }

    @Override
    public String getOrderById(Integer orderId) {
        Integer custId=mapper.selectById(orderId).getCustId();
        Integer proId=mapper.selectById(orderId).getProId();

        return "订单信息："+mapper.selectById(orderId)+
                "用户信息："+customerClient.getCustomerById(custId)+
                "商品信息："+productClient.getPro(proId);
    }
}
